﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BrokerBase.Lib.Policy;

namespace broker.duty.GS
{
    class Class3
    {
        public void Calc2(IPolicyPeriodActing ppa, IDutyActing da)
        {
            if (ppa.SchemePeriodActing.InsurantStates.Contains("身故"))
            {
                string a = ppa.PolicyActing.Policy.SelectedColRateFactors["开始领取年龄"];
                int receiveAge = int.Parse(a.Trim().Substring(0, 2));

                if (ppa.Age < receiveAge)
                {
                    if (ppa.Period < 2)
                    {
                        da.Value = ppa.TotalFee;
                        da.Description = "扣除手续费";
                    }
                    else
                    {
                        da.Description = "现金价值";
                    }

                    ppa.IsCurrentFinish = true;
                }

            }
        }

        public void Calc2(IPolicyPeriodActing ppa, IDutyActing da)
        {
            string a = ppa.PolicyActing.Policy.SelectedColRateFactors["开始领取年龄"];
            int receiveAge = int.Parse(a.Trim().Substring(0, 2));

            string b = ppa.PolicyActing.Policy.SelectedColRateFactors["领取年限"].Trim();

            if (b == "趸领" && ppa.Age == receiveAge)
            {
                da.Value = ppa.Amount;
                ppa.IsCurrentFinish = true;
            }
            else if (b == "年领" && ppa.Age >= receiveAge)
            {
                int deadAge = -1;

                for (int i = receiveAge; i <= ppa.Age; i++)
                {
                    IPolicyPeriodActing ppa2 = ppa.PolicyActing.PeriodActings.FirstOrDefault(p => p.Age == i);

                    if (ppa2 !=null && ppa2.SchemePeriodActing.InsurantStates.Contains("身故"))
                    {
                        deadAge = i;
                        break;
                    }

                }

                if (deadAge == -1)
                {
                    da.Value = ppa.Amount;
                }
                else
                {
                    int endAge = receiveAge + 10;

                    if (ppa.Age < endAge)
                    {
                        da.Value = ppa.Amount;

                        if (ppa.Age == endAge - 1)
                        {
                            ppa.IsCurrentFinish = true;
                        }

                    }
                    
                }
            }

        }
    }
}
